package cc.lj.internal.coupons.application.service;

import cc.lj.internal.api.coupons.dto.CouponsSettlementApiDTO;
import cc.lj.internal.api.coupons.dto.command.CouponsSettlementApiCommand;
import cc.lj.internal.coupons.domain.martcap.model.vo.CapMerchantDO;
import cc.lj.internal.coupons.domain.martcap.service.ICapMerchantDomainService;
import cc.lj.internal.coupons.domain.martcap.service.ICouponsSettlementDomainService;
import cc.lj.internal.coupons.domain.ticket.model.vo.CouponsSettlementDO;
import cc.lj.internal.coupons.domain.ticket.service.ITicketBatchDomainService;
import cc.lj.internal.coupons.interfaces.dto.convert.CouponsSettlementDTOConvertDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 电子券分摊结算 app service
 * @author liangxifeng
 * @date 2022-01-15
 */
@Service
@Slf4j
public class CouponsSettlementAppService {
    @Resource(name = "ticketBatchDomainServiceImpl")
    private ITicketBatchDomainService batchDomainService;

    @Resource(name = "couponsSettlementDomainServiceImpl")
    private ICouponsSettlementDomainService settlementDomainService;

    /**
     * 获取电子券分摊数据
     * @param settlementCommand
     * @return
     */
    public CouponsSettlementApiDTO getShareData(CouponsSettlementApiCommand settlementCommand) {
        /**
         * 通过电子券批次主键查询电子券批次表ticket_batch,并生成商户和卖场分摊数相关数据
         */
        CouponsSettlementDO settlementDO = batchDomainService.createOldShare(settlementCommand.getBatchId());
        //商户展位号
        settlementDO.setMerchantShow(settlementCommand.getMerchantShow());


        /**
         * 封顶额活动商户分摊数据处理
         */
        settlementDomainService.getShareData(settlementDO);
        CouponsSettlementApiDTO settlementApiDTO = CouponsSettlementDTOConvertDO.INSTANCE.convert(settlementDO);
        return settlementApiDTO;
    }
}
